import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import index from '../views/index.vue'
import article from '../views/article.vue'
import aboutview from '../views/AboutView.vue'






Vue.use(VueRouter)

const routes = [
  // 重定向属性
  { path: '/', redirect: '/home' },
  {
    path: '/home',

    component: Home,
    // redirect: '/home',

  }, {
    path: '/article',
    component: article,
  },
  {
    path: '/about',
    name: 'about',
    component: () => import('../views/AboutView.vue')
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/Login.vue')
  },
  {
    path: '/reg',
    name: 'reg',
    component: () => import('../views/Reg.vue')
  },
  {
    path: '/my',
    name: 'my',
    component: () => import('../views/my.vue')
  },
  {
    path: '/publish',
    name: 'publish',
    component: () => import('../views/publish.vue')
  },
  {
    path: '/user/edit',
    name: 'user_edit',
    component: () => import('../views/user_edit.vue')
  },
  {
    path: '/changepassword',
    name: 'changepassword',
    component: () => import('../views/changePassword.vue')
  },
  {
    path: '/search',
    name: 'search',
    component: () => import('../views/search.vue')
  },
  {
    path: '/collectlist',
    name: 'collectlist',
    component: () => import('../views/CollectList.vue')
  },
  {
    path: '/irelease',
    name: 'irelease',
    component: () => import('../views/IRelease.vue')
  },
  {
    path: '/history',
    name: 'history',
    component: () => import('../views/history.vue')
  },
  {
    path: '/retrievepassword',
    name: 'retrievepassword',
    component: () => import('../views/retrievePassword.vue')
  },
]

const router = new VueRouter({
  routes
})

// 挂载路由导航守卫
// router.beforeEach((to, from, next) => {
//   // to将要访问的路径
//   //from代表从哪个路径跳转而来
//   //next 是一个函数 ，代表放行
//   //    next()放行  next('/login')  强制跳转
//   if (to.path === '/login') return next()
//   // 获取token
//   const tokenStr = window.localStorage.getItem('token')
//   if (!tokenStr) return next('/login')
//   next()
// })





export default router
